package com.like.likeutils.network;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;

public class RetrofitUtil {

    static Retrofit mGsonRetrofit = null;
    static Retrofit mXmlRetrofit = null;

    public static Retrofit initGsonRetrofit(String url) {
        if (mGsonRetrofit == null) {
            mGsonRetrofit = new Retrofit.Builder().baseUrl(url)
                    .addConverterFactory(GsonConverterFactory.create()).build();
        }
        return mGsonRetrofit;
    }

    public static Retrofit initXmlRetrofit(String url) {
        if (mXmlRetrofit == null) {
            mXmlRetrofit = new Retrofit.Builder().baseUrl(url)
                    .addConverterFactory(SimpleXmlConverterFactory.create()).build();
        }
        return mXmlRetrofit;
    }

    @SuppressWarnings("unchecked")
    public static <T> T getGsonService(@SuppressWarnings("rawtypes") Class clazz) {
        return (T) mGsonRetrofit.create(clazz);
    }

    @SuppressWarnings("unchecked")
    public static <T> T getXmlService(@SuppressWarnings("rawtypes") Class clazz) {
        return (T) mXmlRetrofit.create(clazz);
    }

}
